<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE html>
<html>
<head>
    <title>学生信息显示</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入bootstrap -->
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
    <!-- 引入JQuery  bootstrap.js-->
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>

    <%--<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">--%>

</head>
<body>
<!-- 顶栏 -->
<jsp:include page="top.jsp"></jsp:include>
<!-- 中间主体 -->
<div class="container" id="content">
    <div class="row mt-3">
        <%--	<jsp:include page="menu.jsp"></jsp:include>--%>
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <div class="row">
                        <h2 class="col-md-5">学生名单管理</h2>
                        <div class="col-md-4"></div>
                        <div class="col-md-3">
                            <button class="btn btn-outline-info" onClick="location.href='/admin/addStudent'">
                                添加用户信息
                                <i class="bi bi-plus-square"></i>
                            </button>
                            <button class="btn btn-outline-danger" onclick="delStu()">删除
                            </button>
                        </div>

                    </div>
                </div>
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th><input type="checkbox" id="checkAll" onclick="selectAll()"></th>
                        <th>学号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>出生年份</th>
                        <th>入学时间</th>
                        <th>学院</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${studentList}" var="item">
                        <tr>
                            <td><input type="checkbox" class="form-check-input ckb" name="check"
                                       value="${item.userid}"/></td>
                            <td>${item.userid}</td>
                            <td>${item.username}</td>
                            <td>${item.sex}</td>
                            <td><fmt:formatDate value="${item.birthyear}" dateStyle="medium"/></td>
                            <td><fmt:formatDate value="${item.grade}" dateStyle="medium"/></td>
                            <td>${item.collegeName}</td>
                            <td>
                                <button class="btn btn-outline-info"
                                        onClick="location.href='/admin/editStudent?id=${item.userid}'">修改
                                </button>
                                <!--弹出框-->
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <div class="card-footer">
                    <c:if test="${pagingVO != null}">
                        <nav style="text-align: center">
                            <ul class="pagination justify-content-center">
                                <li class="page-item"><a class="page-link"
                                                         href="/admin/showStudent?page=${pagingVO.upPageNo}">&laquo;上一页</a>
                                </li>
                                <li class="active page-item"><a class="page-link" href="">${pagingVO.curentPageNo}</a>
                                </li>
                                <c:if test="${pagingVO.curentPageNo+1 <= pagingVO.totalCount}">
                                    <li class="page-item"><a class="page-link"
                                                             href="/admin/showStudent?page=${pagingVO.curentPageNo+1}">${pagingVO.curentPageNo+1}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pagingVO.curentPageNo+2 <= pagingVO.totalCount}">
                                    <li class="page-item"><a class="page-link"
                                                             href="/admin/showStudent?page=${pagingVO.curentPageNo+2}">${pagingVO.curentPageNo+2}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pagingVO.curentPageNo+3 <= pagingVO.totalCount}">
                                    <li class="page-item"><a class="page-link"
                                                             href="/admin/showStudent?page=${pagingVO.curentPageNo+3}">${pagingVO.curentPageNo+3}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pagingVO.curentPageNo+4 <= pagingVO.totalCount}">
                                    <li class="page-item"><a class="page-link"
                                                             href="/admin/showStudent?page=${pagingVO.curentPageNo+4}">${pagingVO.curentPageNo+4}</a>
                                    </li>
                                </c:if>
                                <li class="page-item"><a class="page-link"
                                                         href="/admin/showStudent?page=${pagingVO.totalCount}">最后一页&raquo;</a>
                                </li>
                            </ul>
                        </nav>
                    </c:if>
                </div>
            </div>

        </div>
    </div>
</div>
<div class="container" id="footer">
    <div class="row">
        <div class="col-md-12"></div>
    </div>
</div>
</body>
<script type="text/javascript">
    $("#nav li:nth-child(2) a").addClass("active");

    function confirmd() {
        var msg = "您真的确定要删除吗？！";
        if (confirm(msg) == true) {
            return true;
        } else {
            return false;
        }
    };

    function selectAll() {
        if ($('#checkAll').is(":checked")) {
            $(".ckb").attr("checked", true);
        } else {
            $(".ckb").attr("checked", false);
        }
    }

    function delStu() {
        var ids = '';
        $(".ckb").each(function () {
            if ($(this).is(":checked")) {
                ids += ',' + $(this).val();
            }
        });

        ids = ids.substring(1);
        if (ids.length === 0) {
            alert("请选择要删除的选项");
        } else {
            if (confirm("确定删除？删除后将无法恢复。")) {
                location.href = "/admin/removeStudents?ids=" + ids;
            }
        }

    }


    $("#sub").click(function () {
        $("#form1").submit();
    });

    <c:if test="${pagingVO != null}">
    if (${pagingVO.curentPageNo} == ${pagingVO.totalCount}) {
        $(".pagination li:last-child").addClass("disabled")
    }
    ;

    if (${pagingVO.curentPageNo} == ${1}) {
        $(".pagination li:nth-child(1)").addClass("disabled")
    }
    ;
    </c:if>
</script>
</html>